//
//  PopOverViewController.swift
//  SwiftSina
//
//  Created by 七 on 2017/4/18.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit

class PopOverViewController: UIPresentationController {
    //初始化方法，用于创建负责专场动画的对象
    override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) {
        super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
    }
    //即将布局转场子视图
    override func containerViewWillLayoutSubviews() {
        //修改弹出视图
        //containner容器视图
        //presented 弹出视图
        presentedView?.frame = CGRect(x: 65, y: 55, width: 200, height: 200)
       containerView?.insertSubview(coverView, belowSubview: presentedView!)
    }
    //在容器视图上添加一个蒙版，插入到展示视图下面
    lazy var coverView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        view.frame = UIScreen.main.bounds
        //添加手势
        let tap = UITapGestureRecognizer(target: self, action: #selector(closePresentView))
        view.addGestureRecognizer(tap)
        return view
    }()
    
    @objc func closePresentView(){
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
